<template>
  <div class="all-screen position-relative" ref="register">
    <div ref="rainBg" class="rain-container"></div>
    <div class="rigiter-container">
      <h5 class="rigiter-title">注册</h5>
      <el-form :model="user" ref="registerForm">
        <el-form-item prop="username" :rules="[{ required: true, message: '请输入用户名', trigger: 'blur' }]">
          <h6 class="rigiter-item-title">用户名</h6>
          <el-input v-model="user.username" placeholder="请输入用户名"></el-input>
        </el-form-item>
        <el-form-item required>
          <h6 class="rigiter-item-title">性别</h6>
          <el-radio-group v-model="user.sex">
            <el-radio label="man">男</el-radio>
            <el-radio label="woman">女</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item prop="birthday" :rules="[{ required: true, message: '请选择出生年月', trigger: 'change' }]">
          <h6 class="rigiter-item-title">出生年月</h6>
          <el-date-picker type="date" placeholder="选择出生年月" class="w-100"
            v-model="user.birthday" value-format="yyyy-MM-dd"></el-date-picker>
        </el-form-item>
        <el-form-item prop="birthday" :rules="[{ required: true, message: '请输入密码', trigger: 'blur' }]" >
          <h6 class="rigiter-item-title">密码</h6>
          <el-input v-model="user.password" placeholder="请输入密码"></el-input>
        </el-form-item>
      </el-form>
        <el-button type="primary" class="w-100" @click="regist('registerForm')"
          style="letter-spacing: 16px;">提交信息</el-button>
        <router-link to="/login" class="mt-3 float-right">已有账号,直接登录 >>></router-link>
    </div>
  </div>
</template>
<script>
import api from '@/api'
import TextRain from './rain'
export default {
  title: "个人注册",
  data() {
    return {
      user: {
        username: "",
        password: "",
        sex: 'man',
        birthday: ''
      }
      
    }
  },
  mounted() {
    TextRain(this.$refs.rainBg)
  },
  methods: {
    regist(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          const { user } = this
          this.$post(api.register, user).then(res => {
            this.$message({
              message: '注册成功，请登录',
              type: 'success'
            });
            this.goLogin()
          })
        }
      });
    },
    goLogin() {
      this.$router.push('/login')
    }
  }
}
</script>
<style lang="scss" scoped>
  .rigiter-container {
    position: absolute;
    height: 600px;
    width: 500px;
    top: calc(50% - 300px);
    left: calc(50% - 250px);
    padding: 32px 64px;
    color: #000;
    border-radius: 5px;
    overflow: hidden;
    background: rgba(255, 255, 255, .8);
    box-shadow: 3px 3px 6px 3px rgba(0, 0, 0, .6);
    // &::before{
    //   content: '';
    //   position: absolute;
    //   top: 0;
    //   bottom: 0;
    //   left: 0;
    //   right: 0;
    //   margin: -30px;
    //   filter: blur(20px);
    // }
    .rigiter-title {
      font-size: 36px;
      color: #20A0FF;
      letter-spacing: 50px;
      text-align: center;
      margin-left: 60px;
    }
    .rigiter-item-title {
      
    }
  }
</style>